package vip.xiaonuo.h5.royalty.modular.order.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.h5.royalty.modular.order.param.OrderListParam;
import vip.xiaonuo.h5.royalty.modular.order.param.OrderDetailParam;
import vip.xiaonuo.h5.royalty.modular.order.service.OrderService;
import vip.xiaonuo.h5.royalty.modular.order.vo.OrderPage;
import vip.xiaonuo.h5.royalty.modular.order.vo.OrderDetailVo;

import javax.validation.Valid;

/**
 * 订单控制器
 */
@RestController
@RequestMapping("/h5/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 获取订单列表
     * @param param 查询参数
     * @return 订单列表
     */
    @PostMapping("/getOrderList")
    public CommonResult<OrderPage> getOrderList(@RequestBody @Valid OrderListParam param) {
        OrderPage result = orderService.getOrderList(param);
        return CommonResult.data(result);
    }

    /**
     * 获取订单详情
     * @param param 订单详情参数
     * @return 订单详情
     */
    @PostMapping("/getOrderDetail")
    public CommonResult<OrderDetailVo> getOrderDetail(@RequestBody @Valid OrderDetailParam param) {
        OrderDetailVo result = orderService.getOrderDetail(param);
        return CommonResult.data(result);
    }

    /**
     * 取消订单
     * @param param 订单详情参数
     * @return 操作结果
     */
    @PostMapping("/cancelOrder")
    public CommonResult<Boolean> cancelOrder(@RequestBody @Valid OrderDetailParam param) {
        Boolean result = orderService.cancelOrder(param);
        return CommonResult.data(result);
    }


}
